import { get, post, ResultBean } from '@/utils/request';

// 统一的可扩展类型占位（后续可逐步细化）
export type AnyObj = Record<string, any>;

// ========== 工作流通用 ==========
export function queryParam(appConfId: string) {
  return get<ResultBean<any>>('/formInfo/queryParam', { appConfId });
}

export function saveParam(data: AnyObj) {
  return post<ResultBean<any>>('/formInfo/saveParam', data);
}

export function queryList(data: AnyObj) {
  return post<ResultBean<any>>('/formInfo/queryList', data);
}

export function datasourceQuery(data: AnyObj) {
  return post<ResultBean<any>>('/datasource/queryList', data);
}

export function viewList(data: AnyObj) {
  return post<ResultBean<any>>('/node/taskView/viewList', data);
}

export function viewDesc(viewId: string | number) {
  return get<ResultBean<any>>('/node/taskView/viewDesc', { viewId });
}

export function viewSave(data: AnyObj) {
  return post<ResultBean<any>>('/node/taskView/viewSave', data);
}

export function queryTableList(data: AnyObj) {
  return post<ResultBean<any>>('/tableInfo/queryTableList', data);
}

export function queryTableDesc(formId: string | number) {
  return get<ResultBean<any>>('/tableInfo/queryTableDesc', { formId });
}

export function queryShowColumn(dataId: string | number) {
  return get<ResultBean<any>>('/datasource/queryShowColumn', { dataId });
}

export function queryOutPutByFormId(data: AnyObj) {
  return post<ResultBean<any>>('/outParam/queryOutPutByFormId', data);
}

export function processUpd(data: AnyObj) {
  return post<ResultBean<any>>('/node/processModel/upd', data);
}

export function processExport(data: AnyObj) {
  // 注：原逻辑使用 arraybuffer，此处统一由拦截器处理
  return post<ResultBean<ArrayBuffer>>('/node/processModel/processExport', data, { responseType: 'arraybuffer' as any });
}

export function processModelDel(data: AnyObj) {
  return get<ResultBean<any>>('/node/processModel/del', data);
}

export function checkProcessDel(data: AnyObj) {
  return get<ResultBean<any>>('/node/processModel/checkProcessDel', data);
}

export function cloneProcess(data: AnyObj) {
  return get<ResultBean<any>>('/node/processModel/cloneProcess', data);
}

export function processcreate(data: AnyObj) {
  return post<ResultBean<any>>('/node/processModel/create', data);
}

export function processOutParamSaveOrUp(data: AnyObj) {
  return post<ResultBean<any>>('/node/processModel/processOutParamSaveOrUp', data);
}

export function queryProcessOutConf(data: AnyObj) {
  return get<ResultBean<any>>('/node/processModel/queryProcessOutConf', data);
}

export function queryExecStatus(instanceId: string | number) {
  return get<ResultBean<any>>('/node/processrun/queryExecStatus', { instanceId });
}

export function queryByPage(data: AnyObj) {
  return post<ResultBean<any>>('/node/processModel/queryByPage', data);
}

export function queryInfo(data: AnyObj) {
  return get<ResultBean<any>>('/node/processModel/queryInfo', data);
}

export function processrun(data: AnyObj) {
  return post<ResultBean<any>>('/node/processrun/executeModel', data);
}

export function processCheck(data: AnyObj) {
  return post<ResultBean<any>>('/foreignKey/processCheck', data);
}

// ========== 工作台/待办 ==========
export function queryMyTaskDetail(params: { runTaskId: string | number }) {
  return get<ResultBean<any>>('/node/agencyTasks/queryMyTaskDetail', params);
}

export function queryCompleted(data: AnyObj) {
  return post<ResultBean<any>>('/node/processrun/queryCompleted', data);
}

export function queryWorkPage(data: AnyObj) {
  return post<ResultBean<any>>('/node/processrun/queryWorkPage', data);
}

export function nodeQueryTableList(data: AnyObj) {
  return post<ResultBean<any>>('/tableInfo/nodeQueryTableList', data);
}

export function queryNodeVariable() {
  return get<ResultBean<any>>('/node/processModel/queryNodeVariable');
}

export function querySystemVariable() {
  return get<ResultBean<any>>('/node/processModel/querySystemVariable');
}

export function queryProcessView(instanceId: string | number) {
  return post<ResultBean<any>>(`/node/processrun/queryProcessView/${instanceId}`);
}

export function queryLogs(data: AnyObj) {
  return post<ResultBean<any>>('/node/processrun/queryLogs', data);
}

export function queryUserInfo() {
  return get<ResultBean<any>>('/buttonExec/queryUserInfo');
}

export function queryAllMongo(data: AnyObj) {
  return post<ResultBean<any>>('/usergroup/queryAllMongo', data);
}

export function queryRoleList(data: AnyObj) {
  return post<ResultBean<any>>('/roleinfo/queryRoleList', data);
}

export function upWordStatus(id: string | number) {
  return get<ResultBean<any>>('/node/processrun/upWordStatus', { id });
}

export function complete(data: AnyObj) {
  return post<ResultBean<any>>('/node/agencyTasks/complete', data);
}

export function getUpApprove(data: AnyObj) {
  return get<ResultBean<any>>('/node/processrun/getUpApprove', data);
}

export function getNodeExecStatus(instanceId: string | number) {
  return get<ResultBean<any>>('/node/processrun/getNodeExecStatus', { instanceId });
}

export function dataExec(data: AnyObj) {
  return post<ResultBean<any>>('/datasource/dataExec', data);
}

export function queryTeamTask(data: AnyObj) {
  return post<ResultBean<any>>('/node/agencyTasks/queryTeamTask', data);
}

// ========== 快捷服务 ==========
export function quick(data: AnyObj) {
  return post<ResultBean<any>>('/node/item/quick/set', data);
}

export function queryGroupByItemId(data: AnyObj) {
  return get<ResultBean<any>>('/node/item/quick/queryGroupByItemId', data);
}

export function queryItemQuickList(data: AnyObj) {
  return post<ResultBean<any>>('/node/item/quick/queryQuickList', data);
}

export function queryQuickByModelId(data: AnyObj) {
  return get<ResultBean<any>>('/node/item/quick/queryQuickByModelId', data);
}

export function queryItemDetails(serviceItemId: string | number) {
  return get<ResultBean<any>>('/node/item/queryItemDetails', { serviceItemId });
}

// ========== 定时任务 ==========
export function queryRule() {
  return post<ResultBean<any>>('/timer/queryRule');
}

export function addRecord(data: AnyObj) {
  return post<ResultBean<any>>('/timer/addRecord', data);
}

export function queryTimer() {
  return get<ResultBean<any>>('/timer/queryTimer');
}

export function delTimer(id: string | number, type: string | number) {
  return get<ResultBean<any>>('/timer/delTimer', { id, type });
}

// ========== 其他 ==========
export function delFuncList(data: AnyObj) {
  return post<ResultBean<any>>('/node/taskView/delFuncList', data);
}

export function queryView(dataId: string | number) {
  return get<ResultBean<any>>('/datasource/queryView', { dataId });
}

export function importProcess(data: AnyObj) {
  return post<ResultBean<any>>('/node/processModel/importProcess', data);
}

export function queryByDbName(data: AnyObj) {
  return post<ResultBean<any>>('/tableInfo/queryByDbName', data);
}

export function importBeforeMapping(data: AnyObj) {
  return post<ResultBean<any>>('/node/processModel/importBeforeMapping', data, {
    headers: { 'Content-Type': 'multipart/form-data' }
  });
}

export function querytb(data: AnyObj) {
  return post<ResultBean<any>>('/buttonExec/query/tb21801/4', data);
}

export function queryDesc(data: AnyObj) {
  return get<ResultBean<any>>('/buttonExec/edit/queryDesc/', data);
}

export function queryDatasourceList(data: AnyObj) {
  return post<ResultBean<any>>('/datasource/querySourceAllList', data);
}

export function queryModelView(data: AnyObj) {
  return get<ResultBean<any>>('/node/processModel/queryModelView', data);
}

export function queryDataSourceDetail(data: AnyObj) {
  return get<ResultBean<any>>('/datasource/queryDataSourceDetail', data);
}

// ========== 团队代办 ==========
export function claimUserGroupIds(data: AnyObj) {
  return post<ResultBean<any>>('/task/taskInfo/runExecution/claimUserGroupIds', data);
}

export function claim(params: AnyObj) {
  return get<ResultBean<any>>('/task/taskInfo/runExecution/claim', params);
}

export function chooseTaskByGroup(params: AnyObj) {
  return get<ResultBean<any>>('/task/taskInfo/runExecution/chooseTaskByGroup', params);
}

export function getTeamTaskDetail(params: AnyObj) {
  return get<ResultBean<any>>('/node/agencyTasks/getTeamTaskDetail', params);
}
